package com.star.platforms.controller;

import com.google.firebase.messaging.FirebaseMessaging;
import com.google.firebase.messaging.FirebaseMessagingException;
import com.google.firebase.messaging.Message;
import com.google.firebase.messaging.Notification;
import com.star.platforms.common.ResultBean;
import com.star.platforms.model.User;
import com.star.platforms.service.UserManagerService;
import com.star.platforms.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author sam
 */
@RestController
@RequestMapping("/user")
public class UserManagerController {
    @Autowired
    UserManagerService userManagerService;

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public ResultBean<UserInfo> Login(String username, String password) throws FirebaseMessagingException {
        /*String registrationToken = "d1OjZra6RSqJcIhsu7bpA9:APA91bHb2oety9CW3R5kYDQjOfkd3HiOhYiW5tdoQrw2jxgMIrw6wX_LQb_FkFNOkiuIe3Uw2n3jZ_HpUy06UtGvD9utHbypGWi1uIpy9qTxc55KlI5acZTtoOs6a_mYUapOiLGSoiB8";
        Message message = Message.builder()
                .setNotification(Notification.builder()
                        .setTitle("xxxxx")
                        .setBody("xxxxxxxx")
                        .build())
                //携带数据
                .putData("type", "1")
                .putData("orderId", "28045")
                .setToken(registrationToken)
                .build();

        String response = FirebaseMessaging.getInstance().send(message);
        System.out.println("Successfully sent message: " + response);*/
        return userManagerService.login(username, password);
    }


}
